/**
 * author      : dormi330
 * date        : 2018/6/26
 * project     : mybatis
 * description : 交易父订单, 只在合并支付时起作用, 这里保存支付相关信息
 */

package com.deep.trade.domain.order;

import com.deep.trade.common.BaseEntity;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class OrderSummary extends BaseEntity {

    private String memberId;                    // 会员Id
    private String memberName;                  // 会员Name

    // 金额相关的值
    private BigDecimal platformDiscountMoney;   // 平台优惠金额
    private BigDecimal shopDiscountMoney;       // 店铺优惠金额, 计算值
    private BigDecimal freightMoney;            // 总邮费, 计算值
    private BigDecimal itemMoney;               // 商品总额, 计算值
    private BigDecimal payMoney;                // 实际支付金额, 计算值

    // 支付相关信息(额度外)
    private String payType;                     // 支付方式, 对公/对私
    private String payChannel;                  // 支付渠道
    private Date payDeadLine;                   // 支付超时
    private String payOrderNo;                  // 支付订单号
    private String payStatus;                   // 支付状态
    private Date paidAt;                        // 支付时间

    // 关于退款的记录, 不在这里处理

    private int plock;                          // 锁, 1=被锁, 0=无锁, 在支付时用到

    public OrderSummary() {
        super();
    }

    // 非持久化字段

    private List<TradeOrder> tradeOrderList = new ArrayList<>();

    public void addTradeOrder(TradeOrder tradeOrder) {
        tradeOrder.setOrderSummaryId(this.getId());
        this.tradeOrderList.add(tradeOrder);
    }

    /**
     * - 计算金额
     */
    public void calculateMoney() {
        freightMoney = BigDecimal.ZERO;
        itemMoney = BigDecimal.ZERO;
        payMoney = BigDecimal.ZERO;
        shopDiscountMoney = BigDecimal.ZERO;

        for (TradeOrder tradeOrder : this.tradeOrderList) {
            shopDiscountMoney = shopDiscountMoney.add(tradeOrder.getDiscountMoney());
            freightMoney = freightMoney.add(tradeOrder.getFreightMoney());
            itemMoney = itemMoney.add(tradeOrder.getItemMoney());
            payMoney = payMoney.add(tradeOrder.getPayMoney());
        }
        payMoney = payMoney.subtract(platformDiscountMoney);

    }


    // --- setter / getter ----

    public String getMemberId() {
        return memberId;
    }

    public void setMemberId(String memberId) {
        this.memberId = memberId;
    }

    public BigDecimal getFreightMoney() {
        return freightMoney;
    }

    public void setFreightMoney(BigDecimal freightMoney) {
        this.freightMoney = freightMoney;
    }

    public BigDecimal getPlatformDiscountMoney() {
        return platformDiscountMoney;
    }

    public void setPlatformDiscountMoney(BigDecimal platformDiscountMoney) {
        this.platformDiscountMoney = platformDiscountMoney;
    }

    public String getMemberName() {
        return memberName;
    }

    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    public BigDecimal getShopDiscountMoney() {
        return shopDiscountMoney;
    }

    public void setShopDiscountMoney(BigDecimal shopDiscountMoney) {
        this.shopDiscountMoney = shopDiscountMoney;
    }

    public BigDecimal getItemMoney() {
        return itemMoney;
    }

    public void setItemMoney(BigDecimal itemMoney) {
        this.itemMoney = itemMoney;
    }

    public BigDecimal getPayMoney() {
        return payMoney;
    }

    public void setPayMoney(BigDecimal payMoney) {
        this.payMoney = payMoney;
    }

    public Date getPaidAt() {
        return paidAt;
    }

    public void setPaidAt(Date paidAt) {
        this.paidAt = paidAt;
    }

    public String getPayChannel() {
        return payChannel;
    }

    public void setPayChannel(String payChannel) {
        this.payChannel = payChannel;
    }

    public Date getPayDeadline() {
        return payDeadLine;
    }

    public void setPayDeadline(Date payDeadLine) {
        this.payDeadLine = payDeadLine;
    }

    public String getPayType() {
        return payType;
    }

    public void setPayType(String payType) {
        this.payType = payType;
    }

    public Date getPayDeadLine() {
        return payDeadLine;
    }

    public void setPayDeadLine(Date payDeadLine) {
        this.payDeadLine = payDeadLine;
    }

    public int getPlock() {
        return plock;
    }

    public void setPlock(int plock) {
        this.plock = plock;
    }

    public String getPayOrderNo() {
        return payOrderNo;
    }

    public void setPayOrderNo(String payOrderNo) {
        this.payOrderNo = payOrderNo;
    }

    public String getPayStatus() {
        return payStatus;
    }

    public void setPayStatus(String payStatus) {
        this.payStatus = payStatus;
    }
}
